package com.music.common.presentation.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.music.common.entity.Media;
import com.music.common.entity.UserSettings;
import com.music.common.errorhandler.PresentationException;

public class ViewUploadAction extends Action {

	@SuppressWarnings("finally")
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward actionForward = mapping.findForward("fail");
		try {
			HttpSession session = request.getSession(false);
			UserSettings userSettings = (UserSettings) session.getAttribute("userSettings");
			if (userSettings != null) {
				session.setAttribute("userSettings", userSettings);
				Media media = new Media();
				request.setAttribute("media", media);
				actionForward = (mapping.findForward("success"));
			}
		} catch (Exception ex) {
			throw new PresentationException(ex);
			// System.out.println("Failed at server : \n " +
			// ex.getLocalizedMessage());
		} finally {
			return actionForward;
		}
	}
}
